// https://leetcode.cn/problems/ransom-note/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    bool canConstruct(string ransomNote, string magazine) {
        int m = ransomNote.size();
        int n = magazine.size();

        if (m > n) {
            return false;
        }

        int mp[26];
        for (int i = 0; i < n; i++) {
            mp[magazine[i] - 'a']++;
        }

        for (int i = 0; i < m; i++) {
            mp[ransomNote[i] - 'a']--;

            if (mp[ransomNote[i] - 'a'] < 0) {
                return false;
            }
        }
        return true;
    }
};